package com.btcode.web.core.controller;

import com.btcode.reflect.IClassFinder;
import com.btcode.web.core.annotation.RequestMapping;

public class ControllerFinder implements IClassFinder {

    @Override
    public boolean isMatch(Class<?> loadClass) {
        RequestMapping requestMapping = loadClass.getAnnotation(RequestMapping.class);
        /**
         * 必须要有RequestMapping注解
         */
        if (requestMapping == null) {
            return false;
        }

        Object instance;
        try {
            instance = loadClass.newInstance();
        }
        catch (InstantiationException | IllegalAccessException e) {
            return false;
        }

        /**
         * 必须要继承Controller
         */
        if (instance instanceof Controller) {
            return true;
        }
        return false;
    }

}
